package com.tql.mall.web.controller;

import com.tql.mall.common.constant.PageConstant;
import com.tql.mall.model.order.OrderInfo;
import com.tql.mall.order.client.OrderFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.Map;

/**
 * @Author: tyk
 * @Date: 2023/5/26 16:48
 * @Description:
 */
@Controller
public class OrderWebController {

    @Autowired
    private OrderFeignClient orderFeignClient;


    /**
     * 订单页面
     */
    @GetMapping("trade.html")
    public String trade(Model model) {
        // 订单页面数据
        Map<String, Object> trade = orderFeignClient.trade();
        model.addAllAttributes(trade);
        return "order/trade";
    }

    /**
     * 我的订单
     */
    @GetMapping("myOrder.html")
    public String myOrder() {
        return "order/myOrder";
    }

    /**
     * 退货
     */
    @GetMapping("afterSale.html")
    public String afterSale(Long orderId, Model model) {
        OrderInfo orderInfo = orderFeignClient.getOrderInfo(orderId);
        model.addAttribute(PageConstant.ORDER_ID, orderId);
        model.addAttribute(PageConstant.SHOP_ID, orderInfo.getShopId());
        model.addAttribute(PageConstant.AMOUNT, orderInfo.getTotalAmount());
        return "order/afterSale";
    }

    /**
     * 签收
     */
    @GetMapping("token")
    public String token(Long orderId) {
        orderFeignClient.updateOrderStatus(orderId, 2);
        return "order/myOrder";
    }

}
